include shaiyatools.inc
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
	LOCAL wc:WNDCLASSEX
	LOCAL msg:MSG
	LOCAL hwnd:HWND
	mov   wc.cbSize,SIZEOF WNDCLASSEX
	mov   wc.style, CS_HREDRAW or CS_VREDRAW
	mov   wc.lpfnWndProc, OFFSET WndProc
	mov   wc.cbClsExtra,NULL
	mov   wc.cbWndExtra,NULL
	push  hInstance
	pop   wc.hInstance
	mov   wc.hbrBackground,COLOR_BTNFACE+1
	mov   wc.lpszMenuName,NULL
	mov   wc.lpszClassName,OFFSET ClassName
	invoke LoadIcon,NULL,APP_ICON
	mov   wc.hIcon,eax
	mov   wc.hIconSm,eax	
	invoke LoadCursor,NULL,IDC_ARROW
	mov   wc.hCursor,eax	
	invoke RegisterClassEx, addr wc
	invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,APP_WIDTH,APP_HEIGHT,NULL,NULL,\
           hInst,NULL
	mov   hwnd,eax	
	invoke ShowWindow, hwnd,SW_SHOWNORMAL
	invoke UpdateWindow, hwnd	
	.WHILE TRUE
		invoke GetMessage, ADDR msg,NULL,0,0
		.BREAK .IF (!eax)
		invoke TranslateMessage, ADDR msg
		invoke DispatchMessage, ADDR msg
	.ENDW
	mov     eax,msg.wParam
	ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
	.IF uMsg==WM_DESTROY
		invoke UnRegisterGlobalHotkey,hWnd
		invoke PostQuitMessage,NULL
	.ELSEIF uMsg==WM_CREATE
		invoke CreateAppIcon,hWnd
		invoke CreateAppStyle,hWnd
		invoke RegisterGlobalHotkey,hWnd
		invoke CreateTab,hWnd
	.ELSEIF uMsg==WM_HOTKEY
		.if wParam == GLOBAL_HOTKEY_SHOW
			invoke ShowWindow,hWnd,SW_SHOW
		.elseif wParam == GLOBAL_HOTKEY_HIDE
			invoke ShowWindow,hWnd,SW_HIDE
		.endif
	.ELSEIF uMsg == WM_NOTIFY
		mov eax,lParam
                mov eax,(NMHDR PTR [eax]).code
                .if eax == TCN_SELCHANGE
                    invoke  SendMessage,hTab,TCM_GETCURSEL,0,0
                    .if eax == tabIdHang
                    	invoke MessageBox,NULL,NULL,NULL,MB_OK
                    .elseif eax == tabIdMove
                    	invoke MessageBox,NULL,NULL,offset AppName ,MB_OK
                    .endif
                 .endif
	.ELSE
		invoke DefWindowProc,hWnd,uMsg,wParam,lParam		
		ret
	.ENDIF
	xor eax,eax
	ret
WndProc endp
CreateAppIcon proc hWnd:HWND
	invoke LoadIcon,hInstance,APP_ICON
	invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
	ret
CreateAppIcon endp
CreateAppStyle proc hWnd:HWND
	invoke GetWindowLong,hWnd,GWL_STYLE
	mov ebx,WS_MAXIMIZEBOX
	not ebx
	and eax,ebx
	mov ebx,WS_MINIMIZEBOX
	not ebx
	and eax,ebx
	invoke SetWindowLong,hWnd,GWL_STYLE,eax
	ret
CreateAppStyle endp
RegisterGlobalHotkey proc hWnd:HWND
	invoke RegisterHotKey,hWnd,GLOBAL_HOTKEY_SHOW,MOD_ALT or MOD_CONTROL or MOD_SHIFT,GLOBAL_HOTKEY_SHOW_VALUE
	mov ebx,eax
	invoke RegisterHotKey,hWnd,GLOBAL_HOTKEY_HIDE,MOD_ALT or MOD_CONTROL or MOD_SHIFT,GLOBAL_HOTKEY_HIDE_VALUE
	and eax,ebx
	ret
RegisterGlobalHotkey endp
UnRegisterGlobalHotkey proc	hWnd:HWND
	invoke UnregisterHotKey,hWnd,GLOBAL_HOTKEY_SHOW
	invoke UnregisterHotKey,hWnd,GLOBAL_HOTKEY_HIDE
	ret
UnRegisterGlobalHotkey endp
CreateTab proc hWnd:HWND
	invoke CreateWindowEx,0,ADDR szWndClsTab,\
                                 0,WS_VISIBLE or WS_CHILD or TCS_FIXEDWIDTH ,\
                                 0,0,APP_WIDTH,APP_HEIGHT - 36,\
                                 hWnd,TABID,\
                                 hInstance,0
                mov hTab,eax
                mov tie.imask,TCIF_TEXT
           	mov eax,OFFSET szTabTitleHang
           	mov tie.pszText,eax
           	invoke SendMessage,hTab,TCM_GETITEMCOUNT,0,0
           	mov tabCount,eax
           	invoke SendMessage,hTab,TCM_INSERTITEM,tabCount,ADDR tie
           	mov tabIdHang,eax
           
           	mov tie.imask,TCIF_TEXT
           	mov eax,OFFSET szTabTitleMove
           	mov tie.pszText,eax
           	invoke SendMessage,hTab,TCM_GETITEMCOUNT,0,0
           	mov tabCount,eax
           	invoke SendMessage,hTab,TCM_INSERTITEM,tabCount,ADDR tie
          	 mov tabIdMove,eax
ret
CreateTab endp
end start
